<script type="text/javascript">
	function validateForm()
	{
		var username=document.forms["inputBroker"]["username"].value;
		var error = "";
		if (username==null || username=="")
			error += "Please fill the username<br>"; 
		var password=document.forms["inputBroker"]["password"].value;
		if (password==null || password=="")
			error += "Please fill password"; 
		if (error != "")
			document.getElementById('error').innerHTML=error;
		else
			setBroker(username, password);
	}

	function setBroker(username, password)
	{
		var xmlhttp;
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  	xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {
			    var re = xmlhttp.responseText;
			    if (re == "Have")
			    {
		    		document.getElementById("error").innerHTML="Username is already have";
			    }
			    else
			    {
			    	document.getElementById("showTable").innerHTML=xmlhttp.responseText;
			    }
		    }
		  }
		xmlhttp.open("GET","Controller.php?action=inputBroker&username="+username+"&password="+password,true);
		xmlhttp.send(null);
	}
	
	function showTable()
	{
		var xmlhttp;
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  	xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {
		    		document.getElementById("showTable").innerHTML=xmlhttp.responseText;
		    }
		  }
		xmlhttp.open("GET","Controller.php?action=showTableBroker",true);
		xmlhttp.send(null);
	}

	function deleteBroker(username)
	{
		var xmlhttp;
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  	xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {
		    		document.getElementById("showTable").innerHTML=xmlhttp.responseText;
		    }
		  }
		xmlhttp.open("GET","Controller.php?action=deleteBroker&username=" + username,true);
		xmlhttp.send(null);
	}
</script>
<body onload="showTable()">
<form name='inputBroker' id ='register'>
<fieldset >
<legend>Input broker</legend>
<br> 
<label for='username' >UserName*:</label>
 <input type='text' name='username' id='username' maxlength="50" />
 <br>
<label for='password' >Password*:</label>
<input type='password' name='password' id='password' maxlength="50" />
<br>
<button onclick="validateForm()">Sign up</button>
<input type='reset' value='Reset'>
</fieldset>
</form>
<font color='red'><p id='error'></p></font>
<div id='showTable'></div>
</body>